package com.ch.d0415;

public class demo4 {

    static int i = 0;

    public static void main(String[] args) throws InterruptedException {
        for(int j = 0; j < 100;j++) {
            Thread t = new Thread( ()->{
                for (int k = 0; k <1000;k++){
                   //同步关键字,同时只能有一个线程执行
                    synchronized (demo4.class){
                        // i++不是原子操作
                        i++;
                    }
                }
            });
            t.start();
        }

        Thread.sleep(5000);
        System.out.println("i = " +i);
    }
}
